package TUILayer;

import java.util.Scanner;
import ControlLayer.*;
/**
 * This class is part of an address book system. It's the main menu of the system UI. This menu is associated with the other UIs in the system. 
 *
 * The purpose of this class is to communicate with the user and send the requests to the controllayer. 
 * 
 * @author Anders A.P, Anna K., Danny M.P., Jakob K., Mie P.  
 * @version 1.0
 */
public class MainMenuUI
{
    private AddressBookUI adrUI;
    private DvdUI dvdUI;
    private LoanUI loanUI;

    /**
     * Constructs an instance of MainMenuUI, taking no parameters.
     */   
    public MainMenuUI()
    {      
    }

    /**
     * Starts the UI system in the main menu, allowing the user to move through the different UI classes.
     */   
    public void mainMenuStart()
    {
        boolean exit = false; 
        while (!exit) {
            int choice = writeMainMenu();
            switch (choice) {
                case 1:
                    startAddressBook();
                    break;
                case 2:
                    startDvd();
                    break;
                case 3:
                    startLoan();
                    break;
                default:
                    writeEnd();
                    exit = true;
                    break;
            } 
        }
    }      
    
    /**
     * Initiates the text in the main menu, scanning the user inputs and returns the choice to the caller.
     *
     * @return  choice  The users choice of menu.
     */
    private int writeMainMenu()
    {       
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** MainMenu ***");
        System.out.println(" (1) AddressBook");
        System.out.println(" (2) DVDs");
        System.out.println(" (3) Loan");
        System.out.println(" (4) Close");
        System.out.print("\n Make your choice: ");
            
        int choice = keyboard.nextInt();
            
        return choice;
    }

    /**
     * Initiates the LoanUI class, allowing the user to access the methods contained in LoanUI.
     */    
    private void startLoan() 
    {
        loanUI = new LoanUI();
        loanUI.start();
    }

    /**
     * Initiates the AddressBookUI class, allowing the user to access the methods contained in AddressBookUI.
     */
    private void startAddressBook()
    {
        adrUI= new AddressBookUI();
        adrUI.start();     
    }

    /**
     * Initiates the LoanUI class, allowing the user to access the methods contained in LoanUI.
     */
    private void startDvd()
    {
        dvdUI= new DvdUI();
        dvdUI.start(new DVDCtr());     
    }

    /**
     * Shuts down the system. 
     */
    private void writeEnd()
    {
        System.out.println(" The System is shuting down ");
    }
 }
